home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 201 / 201.xpi / components / privacycontrol.js < prev   
Text File  |  2010-01-11  |  4KB  |  131 lines

  1. /* You may find the license in the LICENSE file */
  2.  
  3. function include(uri) {
  4.     Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
  5.         .getService(Components.interfaces.mozIJSSubScriptLoader).loadSubScript(uri);
  6. }
  7. include('chrome://dta/content/common/xpcom.jsm');
  8.  
  9. var PrivacyControl = {
  10.     initialize : function() {
  11.         // install required observers, so that we may process on shutdown
  12.         const    os = Components.classes['@mozilla.org/observer-service;1']
  13.             .getService(Components.interfaces.nsIObserverService);
  14.         os.addObserver(this, 'profile-change-teardown', false);
  15.         os.addObserver(this, 'xpcom-shutdown', false);
  16.     },
  17.     dispose: function() {
  18.         // always remove observers ;)
  19.         const    os = Components.classes['@mozilla.org/observer-service;1']
  20.             .getService(Components.interfaces.nsIObserverService);
  21.         os.removeObserver(this, 'profile-change-teardown');
  22.         os.removeObserver(this, 'xpcom-shutdown');
  23.     },
  24.     observe: function(subject, topic, data) {
  25.         switch (topic) {
  26.         case 'xpcom-shutdown':
  27.             this.dispose();
  28.             break;
  29.  
  30.         case 'profile-change-teardown':
  31.             this.onShutdown();
  32.             break;
  33.  
  34.         case 'sanitize':
  35.             this.sanitize();
  36.             break;
  37.  
  38.         case 'clean':
  39.             this.clean();
  40.             break;
  41.         }
  42.     },
  43.  
  44.     clean: function() {
  45.         debug('clean()');
  46.         
  47.         // Cleaning prefs
  48.         var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  49.             .getService(Components.interfaces.nsIPrefService).getBranch(
  50.                 'extensions.dta.');
  51.         for each (let e in ['directory', 'filter', 'renaming']) {
  52.             try {
  53.                 prefs.clearUserPref(e);
  54.             }
  55.             catch (ex) {
  56.                 debug("Cannot clear pref: " + e, ex);
  57.             }
  58.         }
  59.         
  60.         // Cleaning files
  61.         try {
  62.             var prof = Components.classes["@mozilla.org/file/directory_service;1"]
  63.                 .getService(Components.interfaces.nsIProperties).get("ProfD",
  64.                     Components.interfaces.nsIFile);
  65.             for each (let e in ['dta_history.xml', 'dta_log.txt', 'dta_queue.sqlite']) {
  66.                 try {
  67.                     var file = prof.clone();
  68.                     file.append(e);
  69.                     if (file.exists()) {
  70.                         file.remove(false);
  71.                     }
  72.                 }
  73.                 catch (ex) {
  74.                     debug('cannot remove: ' + e, ex);
  75.                 }
  76.             }
  77.         }
  78.         catch (oex) {
  79.             debug('failed to clean files: ', oex);
  80.         }
  81.     },
  82.  
  83.     sanitize : function() {
  84.         debug("sanitize()");
  85.         const prefs = Components.classes["@mozilla.org/preferences-service;1"]
  86.             .getService(Components.interfaces.nsIPrefService).getBranch('privacy.');
  87.         
  88.         // in case UI should be used the cleaning will be processed there.
  89.         // Furthermore we have to ensure user wants us to sanitize.
  90.         if (!prefs.getBoolPref('sanitize.promptOnSanitize')
  91.             && prefs.getBoolPref('item.extensions-dta')){
  92.                 this.clean(prefs);
  93.             }
  94.  
  95.     },
  96.     
  97.     get is190() {
  98.         let ai = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULAppInfo);
  99.         let vc = Cc['@mozilla.org/xpcom/version-comparator;1'].getService(Ci.nsIVersionComparator);
  100.         return vc.compare(ai.platformVersion, '1.9.1') < 0;
  101.     },
  102.     
  103.     onShutdown : function() {
  104.         const prefs = Components.classes["@mozilla.org/preferences-service;1"]
  105.             .getService(Components.interfaces.nsIPrefService).getBranch('privacy.');
  106.         
  107.         if (this.is190) {
  108.             // has user pref'ed to sanitize on shutdown?
  109.             if (prefs.getBoolPref('sanitize.sanitizeOnShutdown')){
  110.                 this.sanitize();
  111.             }
  112.             return;
  113.         }
  114.         
  115.         if (prefs.getBoolPref('sanitize.sanitizeOnShutdown') && prefs.getBoolPref('clearOnShutdown.extensions-dta')){
  116.             this.clean();
  117.         }
  118.     }
  119. };
  120. implementComponent(
  121.     PrivacyControl,
  122.     Components.ID("{db7a8d60-a4c7-11da-a746-0800200c9a66}"),
  123.     "@downthemall.net/privacycontrol;1",
  124.     "DownThemAll! Privacy Control",
  125.     [Ci.nsIObserver]
  126. );
  127. PrivacyControl.initialize();
  128.  
  129. function NSGetModule(mgr, spec) {
  130.     return new ServiceModule(PrivacyControl, true);
  131. }